<template>
	<div class="addProject business-workAdd" v-loading="loading">
		<div class="addForm zll-form" >
			<el-form :model="addForm" :rules="rules" ref="addForm" class="demo-ruleForm">
				<el-row :gutter="40">
					<el-col :span="6">
						<p style="line-height: 32px;font-size: 14px;">{{addForm.dutyDay}}</p>
						<div class="ban_ci">
							<li @click="changeBanCi(item)" :class="{'active': currentChooseBanCi == item.value }"
								v-for="(item,index) in onDutyPersonList" :key="index">
								<span>{{item.name + '(' + item.count + ')'}}</span>
							</li>
						</div>
					</el-col>
					<el-col :span="6">
						<el-form-item class="formList" prop="data1" label="今日出勤：">
							<el-input clearable class="input_right" v-model="addForm.totalUserCount"
									  disabled></el-input>
						</el-form-item>
						<el-form-item class="formList" prop="data2" label="本班出勤：">
							<el-input clearable class="input_right"
									  v-model="currentChooseBanCi=='1'?addForm.whiteUserCount:addForm.blackUserCount"
									  disabled></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item class="formList" prop="data3" label="状态：">
							<el-input clearable class="input_right" v-model="addForm.bgStatusCn"
									  disabled></el-input>
						</el-form-item>
						<el-form-item class="formList" prop="data4" label="申报人：">
							<el-input clearable class="input_right"
									  v-model="currentChooseBanCi=='1'?addForm.whiteApplyUser:addForm.blackApplyUser"
									  disabled></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item class="formList" prop="data5" label="核定人：">
							<el-input clearable class="input_right" v-model="addForm.checkUserName"
									  disabled></el-input>
						</el-form-item>
						<el-form-item class="formList" prop="data6" label="完成日期：">
							<el-input clearable class="input_right" v-model="addForm.checkTime"
									  disabled></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<div
					v-if="!isReport&&((currentChooseBanCi == '1' && addForm.saves=='0')||(currentChooseBanCi == '2' && addForm.saves=='0'))"
					class="report_part">
					<p class="noData">本班“报工考勤”尚未创建！点击下方“立即申报”即可开始本班报工及考勤</p>
					<p class="zll-botton" @click="applyOndutyBg" v-if="type !== 'see'"><i
						class="el-icon-circle-plus-outline"></i> 立即申报</p>
				</div>
				<div
					v-if="isReport == 'create'||(currentChooseBanCi == '1' && addForm.saves!='0')||(currentChooseBanCi == '2' && addForm.saves!='0')">
					<div class="con_p">
						<div class="tab_list">
							<li v-for="(item,index) in tabList" :key="index"
								:class="{'active': currentTab == item.type}"
								@click="changeTab(item)" v-if="!item.hidden"
							>{{item.name + '(' + item.num + ')'}}
							</li>
						</div>
						<div class="mine-add" v-if="type =='edit'">
							<span v-if="(checkType !='1'||currentTab=='5')" @click="addTable()"><i class="el-icon-circle-plus"></i></span>
							<span v-if="checkType !='1'||currentTab=='5'" @click.stop="deleteTable()"><i class="el-icon-remove-outline"></i></span>
							<span @click="addKaoQin()" v-if="currentTab < '4'&&checkType !='1'"><i
								class="el-icon-s-custom"></i></span>
						</div>
					</div>
					<div v-if="currentTab < '4'" class="tableList" style="margin-top: 0 !important;">
						<table border="1">
							<tr>
								<th width="40"></th>
								<th>任务名称</th>
								<th>品类</th>
								<th>机台</th>
								<th width="220">规格</th>
								<th>单件万支</th>
								<th>件数</th>
								<th>产能万支</th>
								<th v-if="checkType == '1'">工价(元)</th>
								<th v-if="checkType == '1'">单品薪资</th>
								<th>工序</th>
								<th>姓名</th>
								<th>考勤</th>
								<th v-if="checkType == '1'">薪资(元)</th>
								<th v-if="checkType == '1'">补全</th>
								<th>备注</th>
							</tr>
							<tr class="add_Table" v-for="(item,index) in ondutyBgTaskMap[currentTab]" :key="index">
								<td width="40">
									<el-checkbox v-model="item.checked"></el-checkbox>
								</td>
								<td>
									<el-select v-model="item.taskId" placeholder="" class="text_center" clearable
											   :disabled="type == 'see'||checkType == '1'" @change="changeSelectProduct(item)">
										<el-option :label="v1.planName" :value="v1.id"
												   v-for="(v1,index1) in ondutyProductMap[currentTab]"></el-option>
									</el-select>
								</td>
								<td>
									<el-input v-model="item.itemNameCn" placeholder="" class="text_center" clearable
											  disabled></el-input>
								</td>
								<td>
									<el-input v-model="item.deviceCode" placeholder="" class="text_center" clearable
											  disabled></el-input>
								</td>

								<td>
									<el-input v-model="item.gradeValue" placeholder="" class="text_center" clearable
											  disabled></el-input>
								</td>
								<td>
									<el-input v-model="item.thNumber" placeholder="" class="text_center" clearable
											  disabled></el-input>
								</td>
								<td>
									<el-input @input="item.pieceNum=item.pieceNum.replace(/[^0-9\.]/g,'')"
											  v-model="item.pieceNum" placeholder="" class="text_center" clearable
											  :disabled="type == 'see'||checkType == '1'" @change="changeTotalNum(item)"></el-input>
								</td>
								<td>
									<el-input v-model="item.totalNum" placeholder="" class="text_center" clearable
											  disabled></el-input>
								</td>
								<td v-if="checkType == '1'">
									<el-input @input="item.gongPrice=item.gongPrice.replace(/[^0-9\.]/g,'')"
											  v-model="item.gongPrice" placeholder="" class="text_center" clearable
											  :disabled="type == 'see'" @change="changeGongPrice(item)"></el-input>
								</td>
								<td v-if="checkType == '1'">
									<el-input v-model="item.singlePrice" placeholder="" class="text_center" clearable
											  disabled></el-input>
								</td>

								<td>
									<p v-for="(item2, index2) in item.onDutyBgTaskUsers" :key="index2">
										<el-input v-model="item2.gongxu" placeholder="" class="text_center" clearable
												  :disabled="type == 'see'||checkType == '1'"></el-input>
									</p>
								</td>
								<td width="150">
									<p v-for="(item2, index2) in item.onDutyBgTaskUsers" :key="index2">
										<el-select class="_right" filterable v-model="item2.userId"
												   @change="selectUser(item2)" :disabled="type == 'see'||checkType == '1'">
											<el-option v-for="(item,index) in userList" :key="index"
													   :label="item.userName"
													   :value="item.id" />
										</el-select>
									</p>
								</td>

								<td width="150" >
									<p v-for="(item2, index2) in item.onDutyBgTaskUsers" :key="index2">
										<el-select v-model="item2.kaoQin" :disabled="type == 'see'||checkType == '1'"
												   @change="selectKaoQin(item2)">
											<el-option label="0" value="0"></el-option>
											<el-option label="0.5" value="0.5"></el-option>
											<el-option label="1" value="1"></el-option>
										</el-select>
									</p>
								</td>
								<td width="150" v-if="checkType == '1'">
									<p v-for="(item2, index2) in item.onDutyBgTaskUsers" :key="index2">
										<el-input v-model="item2.userPrice" placeholder="" class="text_center" clearable
												  disabled ></el-input>
									</p>
								</td>

								<td width="150" v-if="checkType == '1'">
									<p v-for="(item2, index2) in item.onDutyBgTaskUsers" :key="index2">
										<el-input @input="item2.buQuan=item.buQuan.replace(/[^0-9\.]/g,'')"
												  v-model="item2.buQuan" placeholder="" class="text_center" clearable
												  :disabled="type == 'see'" ></el-input>
									</p>
								</td>
								<td >
									<el-input v-model="item.remark" placeholder="" class="text_center" clearable
											  :disabled="type == 'see'||checkType == '1'"></el-input>
								</td>
							</tr>
						</table>
					</div>
					<div v-else class="tableList" style="margin-top: 0 !important;">
						<table border="1">
							<tr>
								<th>部门</th>
								<th>姓名</th>
								<th>出勤</th>
								<th>备注</th>
							</tr>
							<tr class="add_Table" v-for="(item,index) in ondutyBgTaskMap[currentTab]" :key="index">
								<td>
									<el-select v-model="item.deptName" placeholder="" class="text_center" filterable
											   :disabled="type == 'see'" @change="changeDept(item)">
										<el-option :label="key" :value="key" v-for="(v1,key) in userDeptList"
												   :key="key"></el-option>
									</el-select>
								</td>
								<td>
									<el-select v-model="item.userId" placeholder="" class="text_center" filterable
											   :disabled="type == 'see'" @change="selectUser(item)">
										<el-option v-for="(item,index) in item.deptUsers||[]" :key="index"
												   :label="item.userName"
												   :value="item.id" :disabled="type == 'see'"/>
									</el-select>
								</td>
								<td>
									<el-select v-model="item.kaoQin" :disabled="type == 'see'"
											   @change="selectKaoQin(item)">
										<el-option label="0" value="0"></el-option>
										<el-option label="0.5" value="0.5"></el-option>
										<el-option label="1" value="1"></el-option>
									</el-select>
								</td>
								<td>
									<el-input v-model="item.remark" placeholder="" class="text_center" clearable
											  :disabled="type == 'see'"></el-input>
								</td>
							</tr>
						</table>
					</div>
					<div class="bottom_nav">
						<p class="zll-botton Info" @click="closeAdd()">关 闭</p>
						<p class="zll-botton" v-if="type !== 'see'" @click="submitForm">保 存</p>
						<p class="zll-botton" style="background-color: red" v-if="checkType == '1' && type !== 'see'" @click="submitForm('1')">核 定</p>
					</div>
				</div>
			</el-form>
		</div>
	</div>
</template>
<script>
	import {getStore} from "@/plugins/localStore";
	import {formatDate} from "@/plugins/formatDate";

	export default {
		props: ['type', 'editData','checkType'],
		data() {
			return {
				loading:false,
				currentTab: '1',
				tabList: [
					{name: '单多支', type: '1', num: 0},
					{name: '伸缩', type: '2', num: 0},
					{name: 'U型', type: '3', num: 0},
					{name: '生产', type: '4', num: 0},
					{name: '非生产', type: '5', num: 0, hidden: true},
				],
				addForm: {
					id: '',
					dutyDay: '',
					whiteUserCount: '',
					blackUserCount: '',
					bgStatus: '',
					bgStatusCn: '',
					checkTime: '',
					checkUserId: '',
					checkUserName: '',
					buQuanUserCount: '',
					totalUserCount: '',
					chuqinTotalUser: '',
					whiteApplyUser: '',
					whiteApplyTime: '',
					blackApplyUser: '',
					blackApplyTime: '',
					whiteSaveTime: '',
					blackSaveTime: '',
					saves: '',
				},


				onDutyPersonList: [{name: '白班', value: '1', count: 0}, {name: '夜班', value: '2', count: 0}],
				currentChooseBanCi: '1',
				isReport: '',
				rules: {},

				currentOndutyProducts: [],
				ondutyBgTaskMap: {
					'1': [],
					'2': [],
					'3': [],
					'4': [],
					'5': [],
				},

				ondutyProductMap: {
					'1': [],
					'2': [],
					'3': [],
					'4': [],
					'5': [],
				},

				user: {},
				userList: [],
				userDeptList: {},
				deptUsers: [],

				count: 0,
			}
		},
		methods: {

			selectKaoQin(item) {
				let userId = item.userId;
				let kaoqin = item.kaoQin;
				if (!userId || !kaoqin) {
					return;
				}
				for (let data of this.ondutyBgTaskMap[this.currentTab]) {
					if (this.currentTab < '4') {
						let onDutyBgTaskUsers = data.onDutyBgTaskUsers;
						if (!onDutyBgTaskUsers) {
							continue;
						}
						for (let taskUser of onDutyBgTaskUsers) {
							let otherUserId = taskUser.userId;
							if (otherUserId == userId && kaoqin != taskUser.kaoQin) {
								taskUser.kaoQin = kaoqin;
							}
						}
					} else {
						if (data.userId == userId && kaoqin != data.kaoQin) {
							data.kaoQin = kaoqin;
						}
					}

				}
			},

			selectUser(val) {
				let user = this.userList.find((item) => item.id == val.userId)
				let userNames = [];
				if (user) {
					val.userName = user.userName;
					for (let data of this.ondutyBgTaskMap[this.currentTab]) {
						if (this.currentTab < '4') {
							let onDutyBgTaskUsers = data.onDutyBgTaskUsers;
							if (!onDutyBgTaskUsers) {
								continue;
							}
							for (let taskUser of onDutyBgTaskUsers) {
								let otherUserId = taskUser.userId;
								if (!userNames.includes(otherUserId) && otherUserId) {
									userNames.push(otherUserId);
								}
								if (otherUserId == val.userId && val.kaoQin != taskUser.kaoQin) {
									taskUser.kaoQin = val.kaoQin;
								}
							}
						} else {
							if (!userNames.includes(data.userId) && data.userId) {
								userNames.push(data.userId);
							}
							if (data.userId == val.userId && val.kaoQin != data.kaoQin) {
								data.kaoQin = val.kaoQin;
							}
						}
					}
					console.log(userNames)
					let index = this.tabList.findIndex((t) => t.type == this.currentTab);
					this.tabList[index].num = userNames.length;
				}

			},
			getSelectUsers() {
				let self = this;
				self.userList = [];
				self.$http({
					url: "/jinl/login/getLoginSelectList",
					method: "post",
				}).then(resp => {
					if (resp.success) {
						self.userList = resp.result;
					}
				});
			},

			getLoginAndDeptSelectList() {
				let self = this;
				self.userList = [];
				self.$http({
					url: "/jinl/login/getLoginAndDeptSelectList",
					method: "post",
				}).then(resp => {
					if (resp.success) {
						self.userDeptList = resp.result;
					}
				});
			},

			changeDept(item) {
				item.userName = '';
				item.userId = '';
				let deptUsers = this.userDeptList[item.deptName];
				this.$set(item, 'deptUsers', deptUsers)
			},

			addKaoQin() {
				let checkCount = 0;
				for (let val of this.ondutyBgTaskMap[this.currentTab]) {
					if (val.checked) {
						++checkCount;
						val.onDutyBgTaskUsers.push({bgTaskId: '', userName: '', userId: '', kaoQin: '1'})
					}
				}
				if(checkCount == 0){
					this.$message.warning('请选中需要增加用户的行！');
				}
			},

			changeSureBanCi(item) {
				let self = this;
				this.currentChooseBanCi = item.value;
				this.isReport = '';
				let dz = [];
				let ss = [];
				let u = [];
				dz = self.currentOndutyProducts.filter((item) => ((item.itemTypeId == '单支连排' || item.itemTypeId == '多支')) && self.currentChooseBanCi == item.whiteDay)
				ss = self.currentOndutyProducts.filter((item) => item.itemTypeId == '伸缩' && self.currentChooseBanCi == item.whiteDay)
				u = self.currentOndutyProducts.filter((item) => item.itemTypeId == 'U型' && self.currentChooseBanCi == item.whiteDay)
				self.ondutyProductMap['1'] = dz;
				self.ondutyProductMap['2'] = ss;
				self.ondutyProductMap['3'] = u;

				self.ondutyBgTaskMap = {
					'1': [],
					'2': [],
					'3': [],
					'4': [],
					'5': [],
				};
				self.getOnDutyBgTaskList();
			},

			changeBanCi(item) {//切换白夜班
				let self = this;
				if (this.currentChooseBanCi == item.value) {
					return;
				}
				if (this.isReport == 'create') {
					self.$confirm('数据未保存，确定切换班次？', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						self.changeSureBanCi(item);
					});
				} else {
					self.changeSureBanCi(item);
				}
			},
			changeTab(val) {
				this.currentTab = val.type
			},
			addTable() {
				if (this.currentTab < '4') {
					this.ondutyBgTaskMap[this.currentTab].push({
						id: '',
						bgId: '',
						dutyDay: '',
						whiteDay: '',
						itemName: '',
						deviceCode: '',
						planName: '',
						gradeValue: '',
						thNumber: '',
						pieceNum: '',
						totalNum: '',
						taskId: '',
						gongPrice: '',
						singlePrice: '',
						remark: '',
						onDutyBgTaskUsers: [{bgTaskId: '', userName: '', userId: '', kaoQin: '1',gongxu:''}],
					});
				} else {
					this.ondutyBgTaskMap[this.currentTab].push({
						bgId: '',
						dutyDay: '',
						whiteDay: '',
						userId: '',
						userName: '',
						remark: '',
						kaoQin: '1',
						itemType: this.currentTab,
					});
				}
			},
			deleteTable() {//删除table
				let tableList = [];
				this.ondutyBgTaskMap[this.currentTab].filter(val => {
					if (!val.checked) {
						tableList.push(val)
					}
				});
				this.ondutyBgTaskMap[this.currentTab] = tableList
			},

			operate(status) {
				let self = this;
				if (self.count == 0) {
					let deviceCodes = [];
					let params = {
						bgId: self.addForm.id,
						whiteDay: self.currentChooseBanCi,
						dutyDay: self.addForm.dutyDay,
						applyName: self.user.userName,
						onDutyBgTasks: [],
						onDutyBgShenchangs: [],
						bgStatus:''
					};
					if(self.checkType == '1'){
						params.notProduct = '1';
					}
					if('1' == status){
						params.bgStatus = status;
						params.checkUserId = self.user.id;
						params.checkUserName = self.user.userName;
					}else{
						delete params.checkUserId;
						delete params.checkUserName;
					}
					for (let key in self.ondutyBgTaskMap) {
						let products = this.ondutyBgTaskMap[key];
						if (!products || products.length == 0) {
							continue;
						}
						for (let data of products) {
							data.itemName = key;
							if (key < '4') {
								if (!data.pieceNum) {
									self.$message.warning('请输入件数！');
									return;
								}
								if (!data.taskId) {
									self.$message.warning('请选择任务！');
									return;
								}

								if (deviceCodes.includes(data.deviceCode)) {
									self.$message.warning('设备' + data.deviceCode + '只能选择一次！');
									return;
								}
								deviceCodes.push(data.deviceCode);
								let onDutyBgTaskUsers = data.onDutyBgTaskUsers;
								for (let user of onDutyBgTaskUsers) {
									if (!user.userId) {
										self.$message.warning('请选择姓名！');
										return;
									}
									if (!user.gongxu) {
										self.$message.warning('请填写工序！');
										return;
									}
								}
								if(self.checkType == '1'&&status == 1){
									if (!data.gongPrice) {
										self.$message.warning('请输入工价！');
										return;
									}
								}
								params.onDutyBgTasks.push(data)
							} else {
								params.onDutyBgShenchangs.push(data)
							}
						}
					}
					if (params.onDutyBgTasks.length == 0 && params.onDutyBgShenchangs.length == 0) {
						self.$message.warning('请填写数据！');
						return;
					}
					if(status == 1){
						self.$confirm('一旦提交则无法更改,是否继续核定提交？', '提示', {
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							type: 'warning'
						}).then(() => {
							self.batchUpdateOnDutyBgTasks(params);
						});
					}else{
						self.batchUpdateOnDutyBgTasks(params);
					}
				}
			},

			batchUpdateOnDutyBgTasks(params){
				let self = this;
				++self.count;
				self.$http({
					url: '/jinl/bgTask/batchUpdateOnDutyBgTasks',
					method: "post",
					data: JSON.stringify(params),
					dataType: 'json',
					contentType: "application/json",
				}).then(resp => {
					if (resp.success) {
						self.$notify({title: '提示', message: "操作成功！", type: 'success'});
						self.count--;
						self.$eventBus.$emit("updateOndutyTaskList");
						return;
					}
					self.$notify({title: '提示', message: resp.message, type: 'error'});
					self.count--;
				});
			},

			submitForm(status) {
				let self = this;
				self.$refs['addForm'].validate((valid) => {
					if (valid) {
						self.operate(status);
					} else {
						return false;
					}
				});
			},
			closeAdd() {
				this.$eventBus.$emit("updateOndutyTaskList");
			},

			changeSelectProduct(pod) {
				let product = this.ondutyProductMap[this.currentTab].find((item) => item.id == pod.taskId);
				pod.taskId = '';
				pod.itemName = '';
				pod.deviceCode = '';
				pod.gradeValue = '';
				pod.thNumber = '';
				if (product) {
					pod.taskId = product.id;
					pod.planName = product.planName;
					pod.itemRefName = product.itemTypeId;
					pod.itemNameCn = product.itemTypeId;
					pod.deviceCode = product.deviceCode;
					pod.gradeValue = product.gradeValue;
					pod.thNumber = product.thNumber;
				}
				if (pod.pieceNum && pod.thNumber) {
					let totalNum = parseFloat(pod.pieceNum) * parseFloat(pod.thNumber);
					pod.totalNum = totalNum.toFixed(2);
				}
			},

			changeTotalNum(pod) {
				if (pod.pieceNum && pod.thNumber) {
					let totalNum = parseFloat(pod.pieceNum) * parseFloat(pod.thNumber);
					pod.totalNum = totalNum.toFixed(2);
					if(pod.gongPrice){
						totalNum = parseFloat(pod.gongPrice) * parseFloat(pod.totalNum);
						pod.singlePrice = totalNum.toFixed(1);
					}
				}
			},

			changeGongPrice(pod){
				if (pod.gongPrice && pod.totalNum) {
					let totalNum = parseFloat(pod.gongPrice) * parseFloat(pod.totalNum);
					pod.singlePrice = totalNum.toFixed(1);
					let onDutyBgTaskUsers = pod.onDutyBgTaskUsers;
					if (!onDutyBgTaskUsers) {
						return;
					}
					let totalKaoQin = 0.0;
					for(let user of onDutyBgTaskUsers){
						totalKaoQin+= parseFloat(user.kaoQin);
					}
					if(totalKaoQin > 0){
						for(let user of onDutyBgTaskUsers){
							let kaoQin = parseFloat(user.kaoQin);
							let singlePrice = totalNum*(kaoQin/totalKaoQin);
							user.userPrice = singlePrice.toFixed(1)
						}
					}
				}
			},

			getOnDutyProductsByDutyDay() {
				let self = this;
				self.currentOndutyProducts = [];
				self.$http({
					url: "/jinl/dutyprod/getOnDutyProductsByDutyDay",
					method: "post",
					params: {dutyDay: self.addForm.dutyDay}
				}).then(resp => {
					self.loading = false;
					if (resp.success) {
						self.currentOndutyProducts = resp.result;
						let dz = [];
						let ss = [];
						let u = [];
						dz = self.currentOndutyProducts.filter((item) => ((item.itemTypeId == '单支连排' || item.itemTypeId == '多支')) && self.currentChooseBanCi == item.whiteDay)
						ss = self.currentOndutyProducts.filter((item) => item.itemTypeId == '伸缩' && self.currentChooseBanCi == item.whiteDay)
						u = self.currentOndutyProducts.filter((item) => item.itemTypeId == 'U型' && self.currentChooseBanCi == item.whiteDay)
						self.ondutyProductMap['1'] = dz
						self.ondutyProductMap['2'] = ss
						self.ondutyProductMap['3'] = u;
						console.log('===self.ondutyProductMap====')
						console.log(self.currentOndutyProducts);
						console.log(self.ondutyProductMap);
					}
				});
			},

			getOnDutyBgTaskList() {
				let self = this;
				self.$http({
					url: "/jinl/bgTask/getOnDutyBgTaskList",
					method: "post",
					params: {whiteDay: self.currentChooseBanCi, bgId: self.addForm.id}
				}).then(resp => {
					self.loading = false;
					if (resp.success) {
						for (let key in resp.result) {
							let datas = resp.result[key];
							let users = [];
							for (let data of datas) {
								self.$set(data, 'check', false);
								self.$set(data, 'gongPrice', data.gongPrice||'');
								self.$set(data, 'singlePrice', data.singlePrice||'');
								if(key < '4'){
									let onDutyBgTaskUsers = data.onDutyBgTaskUsers;
									if (!onDutyBgTaskUsers) {
										continue;
									}
									for (let taskUser of onDutyBgTaskUsers) {
										let otherUserId = taskUser.userId;
										self.$set(taskUser, 'buQuan', taskUser.buQuan||'');
										self.$set(taskUser, 'userPrice', taskUser.userPrice||'');
										if (!users.includes(otherUserId) && otherUserId) {
											users.push(otherUserId);
										}
									}
									let totalNum = parseFloat(data.pieceNum) * parseFloat(data.thNumber);
									data.totalNum = totalNum.toFixed(2);
								} else {
									if (!users.includes(data.userId) && data.userId) {
										users.push(data.userId);
									}
									let deptUsers = self.userDeptList[data.deptName];
									this.$set(data, 'deptUsers', deptUsers)
								}
							}
							let index = parseInt(key) -1;
							self.tabList[index].num = users.length;
						}
						self.ondutyBgTaskMap = resp.result;
						console.log('===self.getOnDutyBgTaskList====')
						console.log(resp.result);
					}
				});
			},

			getOnDutyAndWhiteDay() {
				let self = this;
				self.$http({
					url: "/jinl/dutyprod/getOnDutyAndWhiteDay",
					method: "post",
				}).then(resp => {
					if (resp.success) {
						self.currentChooseBanCi = resp.result.whiteDay;
						self.getOnDutyProductsByDutyDay();
						self.getOnDutyBgTaskList();
					}
				});
			},

			applyOndutyBg() {
				this.isReport = 'create';
			}

		},
		mounted() {
			this.getSelectUsers();
			this.getLoginAndDeptSelectList();
		},

		watch: {
			editData(val) {
				console.log('==========editData==============')
				console.log(val)
				this.loading = true;
				for (let key in this.addForm) {
					this.addForm[key] = val[key] || ''
				}
				this.user = getStore();
				if(this.checkType == 1){
					this.tabList[4].hidden =false;
					if(!this.addForm.checkUserName){
						this.addForm.checkUserName = this.user.userName;
					}
				}

				if (this.type == 'edit') {
					if (!this.addForm.whiteApplyUser) {
						this.addForm.whiteApplyUser = this.user.userName;
					}
					if (!this.addForm.blackApplyUser) {
						this.addForm.blackApplyUser = this.user.userName;
					}
				}
				this.onDutyPersonList[0].count = this.addForm.whiteUserCount;
				this.onDutyPersonList[1].count = this.addForm.blackUserCount;
				this.getOnDutyAndWhiteDay();
			},
		},
		components: {}
	}
</script>
<style lang="scss" scoped>
	@import "@/style/dialog.scss";

	.business-workAdd.addProject {
		position: relative;
		padding-bottom: 40px;
		min-height: 100%;

		.con_p {
			display: flex;
			justify-content: space-between;
			margin-top: 20px;
			margin-bottom: 10px;

			.tab_list {
				display: flex;

				li {
					width: 140px;
					line-height: 32px;
					border-bottom: 1px solid #fff;
					text-align: center;
					cursor: pointer;
					color: #918d8d;

					&.active {
						color: #2196f3;
						font-size: 14px;
						border-bottom: 1px solid #2196f3;
					}
				}
			}
		}

		.report_part {
			height: 400px;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.noData {
				text-align: center;
				color: #918d8d;
				line-height: 40px;
			}

			.zll-botton {
				width: 120px;
			}
		}

		.bottom_nav {
			display: flex;
			justify-content: center;
			position: absolute;
			width: 100%;
			bottom: 20px;
			z-index: 1111;

			.zll-botton {
				margin: 0 20px;
			}
		}

		.ban_ci {
			display: flex;

			li {
				width: 130px;
				background: #ddd;
				color: #918d8d;
				line-height: 30px;
				height: 30px;
				text-align: center;
				margin-right: 5px;
				cursor: pointer;
				display: flex;
				align-items: center;
				justify-content: center;

				&.active {
					background: #2196f3;
					color: #fff;
				}

				img {
					width: 20px;
					height: 20px;
					margin-right: 5px;
				}
			}
		}

		.formList {
			margin-bottom: 0px;
			height: 32px;
		}

		.tableList {
			margin-bottom: 20px;

			table {
				tr {
					background: #fff !important;

					td {
						padding: 1px 3px;
					}
				}
			}
		}
	}
</style>